package com.icss.th.common.config;

import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

/**
 * 系统配置类
 * @author CSI-peijn
 *
 */
public class SystemConfig 
{
	/**
	 * mysql数据连接jndi
	 */
	public static final String JNDI_MYSQL = get("JNDI_MYSQL");
	
	/**
	 * mysql数据连接jndi
	 */
	public static final String JNDI_SQLSERVER = get("JNDI_SQLSERVER");
	
	/**
	 * 判断科目是否显示的试题数量阈值
	 */
	public static final String SUBJECT_EXAM_COUNT = get("SUBJECT_EXAM_COUNT");
	
	/**
	 * 全文检索引擎类型
	 */
	public static final String FULLTEXT_TYPE = get("FULLTEXT_TYPE");
	
	/**
	 * 全文检索exam索引路径
	 */
	public static final String EXAM_INDEX_PATH = get("EXAM_INDEX_PATH");
	
	/**
	 * 全文检索paper索引路径
	 */
	public static final String PAPER_INDEX_PATH = get("PAPER_INDEX_PATH");
	
	/**
	 * 分页-每页显示多少条
	 */
	public static final String COUNT_PER_PAGE = get("COUNT_PER_PAGE");
	
	/**
	 * 存储类型
	 */
	public static final String DB_TYPE = get("DB_TYPE");
	
	/**
	 * mongodb地址
	 */
	public static final String MONGODB_DBNAME = get("MONGODB_DBNAME");
	
	/**
	 * mongodb库名
	 */
	public static final String MONGODB_ADDRESS = get("MONGODB_ADDRESS");
	
	/**
	 * mongodb用户名
	 */
	public static final String MONGODB_USER = get("MONGODB_USER");
	
	/**
	 * mongodb密码
	 */
	public static final String MONGODB_PWD = get("MONGODB_PWD");
	
	//////////////////////////////////华丽的分割线，上方为系统配置项//////////////////////////////
	
	/**
	 * 系统配置文件路径，相对于根
	 */
	private static final String CONFIG_PATH = "system";
	
	private static Map<String, String> configMap;
	
	/**
	 * 初始化系统配置文件
	 */
	private static void init()
	{
		configMap = new HashMap<String, String>();
		
		ResourceBundle resource = ResourceBundle.getBundle(CONFIG_PATH);
		if (resource != null)
		{
			configMap.put("JNDI_MYSQL", resource.getString("JNDI_MYSQL"));
			configMap.put("JNDI_SQLSERVER", resource.getString("JNDI_SQLSERVER"));
			configMap.put("SUBJECT_EXAM_COUNT", resource.getString("SUBJECT_EXAM_COUNT"));
			configMap.put("FULLTEXT_TYPE", resource.getString("FULLTEXT_TYPE"));
			configMap.put("EXAM_INDEX_PATH", resource.getString("EXAM_INDEX_PATH"));
			configMap.put("PAPER_INDEX_PATH", resource.getString("PAPER_INDEX_PATH"));
			configMap.put("COUNT_PER_PAGE", resource.getString("COUNT_PER_PAGE"));
			configMap.put("MONGODB_ADDRESS", resource.getString("MONGODB_ADDRESS"));
			configMap.put("MONGODB_DBNAME", resource.getString("MONGODB_DBNAME"));
			configMap.put("DB_TYPE", resource.getString("DB_TYPE"));
			configMap.put("MONGODB_USER", resource.getString("MONGODB_USER"));
			configMap.put("MONGODB_PWD", resource.getString("MONGODB_PWD"));
		}
	}
	
	/**
	 * 得到系统配置值
	 * @param key
	 * @return
	 */
	private static String get(String key)
	{
		if (configMap == null)	init();
		return configMap.get(key);
	}
}
